<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AdminRoleRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = $this->route('admin_role') ? $this->route('admin_role')->id : null; //获取当前需要排除的id
        return [
            'name' => 'required|max:50|unique:admin_roles,name,' . $id,
            'status' => 'required|boolean',
        ];
    }

    /**
     * Get custom messages for validator errors.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'name.required' => '名称不能为空.',
            'name.max' => '名称不能大于50位字符.',
            'name.unique' => '名称已存在.',
            'status.required' => '状态不能为空.',
            'status.boolean' => '状态操作有误.',
        ];
    }
}
